import 'package:flutter/material.dart';
import 'support/activity_text_style.dart';
import 'support/theme_color.dart';
import 'widget/activity_border_container.dart';
import 'widget/activity_linear_gradient_container.dart';
import 'widget/activity_scaffold.dart';
import 'widget/gesture_assets_image.dart';
import 'package:flutter_public/flutter_public.dart';

/// FileName example_page
///
/// @Author lax
/// @Date 2024/6/12
///
/// @Description

class ExamplePage extends StatefulWidget {
  const ExamplePage({super.key});

  @override
  State<StatefulWidget> createState() {
    return _ExamplePageState();
  }
}

class _ExamplePageState extends State<ExamplePage> {
  List<String> dataSource = ['2024-04-10', '2024-04-11'];

  int currentIndex = 0;

  @override
  Widget build(BuildContext context) {
    return ActivityScaffold(
      appBar: ClearAppBar(title: '示例'),
      body: Column(
        children: [
          dayListView(),
          Expanded(
            child: SeparatedScrollColumn(
              physics: const AlwaysScrollableScrollPhysics(),
              padding: SafeEdgeInsets.symmetric(horizontal: 16, vertical: 16),
              separator: const SizedBox(height: 16),
              children: [
                contentListView(),
                Visibility(
                  visible: currentIndex == 0,
                  child: dressView(),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  /// 着装
  Widget dressView() {
    return ActivityLinearGradientContainer(
      radius: 16,
      child: SeparatedColumn(
        padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
        separator: const SizedBox(height: 12),
        children: [
          const SizedBox(
            width: double.infinity,
            child: Text(
              '着装',
              style: ActivityTextStyle(fontSize: 16),
            ),
          ),
          ActivityLinearGradientContainer(
            radius: 16,
            child: const GestureAssetsImage(
                url:
                    'https://beltnroad-api.ab-inbev.cn/api/FileManager/DownloadBlob?url=6ECAC81813CAABFA4CAA2DCB00938340E1813292819E3DE3F5553FD728107A8B82112AA806E3BBA3144BA0A5072F6FDBED81EC32AFF56ACDC9C87893C7D34DD525CA27E84552D62F39DAA1203DBA7ED29AC2D3A836E9668771253D0594BE3619FA19DB4F0BF02ED1AA8F036ACC932DFDCFE9F007CB9058AC8E76A986EB1D079F61475C6B1C8F338C005477FD677AA8B5.png',
                radius: 16),
          ),
        ],
      ),
    );
  }

  /// 日期
  Widget dayListView() {
    return SeparatedScrollRow(
      padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
      separator: const SizedBox(width: 16),
      children: dataSource.map((e) {
        final index = dataSource.indexOf(e);
        return GestureDetector(
          onTap: () {
            setState(() {
              currentIndex = index;
            });
          },
          child: dayListItem(e: e, highlight: index == currentIndex),
        );
      }).toList(),
    );
  }

  Widget dayListItem({required String e, required bool highlight}) {
    return ActivityBorderContainer(
      highlight: highlight,
      padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 8),
      child: Text(
        e,
        textAlign: TextAlign.center,
        style: ActivityTextStyle(
            color: highlight ? ThemeColor.activityPrimaryRed : null),
      ),
    );
  }

  /// 日程
  Widget contentListView() {
    var data = [
      {
        "Id": "e68db761-de4d-41d7-b27b-d3b165b668df",
        "StartDate": "2024-04-10 08:30:00",
        "EndDate": "2024-04-10 08:00:00",
        "Content": "销售培训（NSC与会人员参加）",
        "Speaker": "",
        "Address": ""
      },
      {
        "Id": "0355aaf4-ef66-4de3-8832-fc7c156aa78c",
        "StartDate": "2024-04-10 08:30:01",
        "EndDate": "2024-04-10 13:00:00",
        "Content": "体能活动（人才日人员参加）",
        "Speaker": "",
        "Address": ""
      },
      {
        "Id": "fdff912f-bd01-42b0-b4a3-0de895a4164a",
        "StartDate": "2024-04-10 13:20:00",
        "EndDate": "2024-04-10 14:00:00",
        "Content": "午餐",
        "Speaker": "",
        "Address": ""
      },
      {
        "Id": "40201d00-0cd7-47e5-aab6-58af6e6a67a8",
        "StartDate": "2024-04-10 14:40:00",
        "EndDate": "2024-04-10 18:30:00",
        "Content": "分组研讨会",
        "Speaker": "",
        "Address": ""
      },
      {
        "Id": "c7404391-ee38-4500-ac38-d064b2d2791c",
        "StartDate": "2024-04-10 19:00:00",
        "EndDate": "2024-04-10 21:00:00",
        "Content": "百威菁英晚宴",
        "Speaker": "",
        "Address": ""
      }
    ];
    if (currentIndex == 1) {
      data = [
        {
          "Id": "DDF7ACF0-BE62-467C-A4D3-CBA72F3CBA4A",
          "StartDate": "2024-03-25 09:00:00",
          "EndDate": "2024-03-25 09:30:00",
          "Content": "开场",
          "Speaker": "",
          "Address": ""
        },
        {
          "Id": "DF5FF144-3E05-43DE-BB90-A73C092B8FE2",
          "StartDate": "2024-03-25 09:30:00",
          "EndDate": "2024-03-25 10:10:00",
          "Content": "制胜2024",
          "Speaker": "",
          "Address": ""
        },
        {
          "Id": "E5FE74AA-1003-4DA1-A30C-AD7649743D51",
          "StartDate": "2024-03-25 10:30:00",
          "EndDate": "2024-03-25 11:15:00",
          "Content": "百威增长策略",
          "Speaker": "",
          "Address": ""
        },
        {
          "Id": "13E81595-77B1-4A6D-B378-39503193AECE",
          "StartDate": "2024-03-25 11:15:00",
          "EndDate": "2024-03-25 12:00:00",
          "Content": "超高端增长策略",
          "Speaker": "",
          "Address": ""
        },
        {
          "Id": "0C0CE5D9-090C-467F-85F6-E4AC04B35649",
          "StartDate": "2024-03-25 12:00:00",
          "EndDate": "2024-03-25 13:00:00",
          "Content": "午餐",
          "Speaker": "",
          "Address": ""
        },
        {
          "Id": "63A9317D-7021-4597-BB5A-212572D232F1",
          "StartDate": "2024-03-25 13:00:00",
          "EndDate": "2024-03-25 13:15:00",
          "Content": "哈尔滨增长策略",
          "Speaker": "",
          "Address": ""
        },
        {
          "Id": "503C3303-BB43-4A6E-829E-3179DE8F59E7",
          "StartDate": "2024-03-25 13:15:00",
          "EndDate": "2024-03-25 14:00:00",
          "Content": "家庭消费渠道重点策略",
          "Speaker": "",
          "Address": ""
        },
        {
          "Id": "1226690A-47B1-499C-91A0-681B199E81AE",
          "StartDate": "2024-03-25 14:20:00",
          "EndDate": "2024-03-25 14:50:00",
          "Content": "先锋购生态体系构建",
          "Speaker": "",
          "Address": ""
        },
        {
          "Id": "FD71BB40-C360-4B80-B56B-C251B76AE1D0",
          "StartDate": "2024-03-25 14:50:00",
          "EndDate": "2024-03-25 15:05:00",
          "Content": "经销商能力值和经销商返利",
          "Speaker": "",
          "Address": ""
        },
        {
          "Id": "A025FAB6-845C-419D-A507-E7C92D4524EB",
          "StartDate": "2024-03-25 15:05:00",
          "EndDate": "2024-03-25 15:20:00",
          "Content": "精简·聚焦·执行",
          "Speaker": "",
          "Address": ""
        },
        {
          "Id": "175C92C2-1CBA-4900-8F5D-EC1BEBAD1A3B",
          "StartDate": "2024-03-25 15:20:00",
          "EndDate": "2024-03-25 15:30:00",
          "Content": "市场走访介绍",
          "Speaker": "",
          "Address": ""
        },
        {
          "Id": "326FDC9A-316E-46E9-B8CC-2480B5062B7A",
          "StartDate": "2024-03-25 16:00:00",
          "EndDate": "2024-03-25 18:30:00",
          "Content": "沉浸式市场走访",
          "Speaker": "",
          "Address": ""
        },
        {
          "Id": "A2C0BB7C-001F-4053-97DC-97A153A9EA88",
          "StartDate": "2024-03-25 18:30:00",
          "EndDate": "2024-03-25 20:30:00",
          "Content": "晚餐",
          "Speaker": "",
          "Address": ""
        },
        {
          "Id": "CD1E0061-8F29-4A03-BCC1-908809D8A417",
          "StartDate": "2024-03-25 20:30:00",
          "EndDate": "2024-03-25 22:00:00",
          "Content": "夜场",
          "Speaker": "",
          "Address": ""
        },
      ];
    }
    // final nowSeconds = DateTime.now().millisecondsSinceEpoch;
    final nowSeconds =
        DateTime.parse('2024-04-10 14:44:44').millisecondsSinceEpoch;
    return ListView.separated(
      shrinkWrap: true,
      physics: const NeverScrollableScrollPhysics(),
      padding: EdgeInsets.zero,
      itemCount: data.length,
      separatorBuilder: (context, index) {
        return const SizedBox(height: 16);
      },
      itemBuilder: (context, index) {
        final model = data[index];
        final dateTime =
            model['StartDate']?.dateTimeString(dateType: DateType.kHM);
        final start = DateTime.tryParse(model['StartDate'] ?? '')
                ?.millisecondsSinceEpoch ??
            0;
        final end =
            DateTime.tryParse(model['EndDate'] ?? '')?.millisecondsSinceEpoch ??
                0;
        final isNow = nowSeconds > start && nowSeconds < end;
        return ActivityLinearGradientContainer(
          padding: const EdgeInsets.all(16),
          highlight: isNow,
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(
                '$dateTime  |  ',
                style: ActivityTextStyle(
                  fontSize: 16,
                  color: isNow ? ThemeColor.activityPrimaryRed : null,
                  // fontFamily: isNow ? Static.fontNameBudweiserEnglish : null,
                ),
              ),
              Expanded(
                child: Text(
                  '${model['Content']}',
                  style: ActivityTextStyle(
                      fontSize: 16,
                      color: isNow ? ThemeColor.activityPrimaryRed : null),
                ),
              ),
            ],
          ),
        );
      },
    );
  }
}
